<?php

class dbaTpl
{

    function dbaTpl (&$dba)
    {
        $this->dba = &$dba;
    }
    
    function register ($name, $filename, $type, $site_id)
    {
        return $this->dba->query("insert into ".$this->dba->tableforwarder."_cmsTpl (name,filename,type,site_id) values ('$name', '$filename', '$type', '$site_id');");
    }
    
    function unregister ($id)
    {
        return $this->dba->query("delete from ".$this->dba->tableforwarder."_cmsTpl where id=$id;");
    }
    
    function update ($id,$name)
    {
        return $this->dba->query("update ".$this->dba->tableforwarder."_cmsTpl set name=".$this->dba->quote($name)." where id=$id;");
    }
    
    function get ($id)
    {
        $sth = $this->dba->query("select * from ".$this->dba->tableforwarder."_cmsTpl where id=$id;");
        if (is_object($sth))
        {
            $row = $sth->fetch_row_Array();
            $sth->free();
            return $row;
        }
    }
    
    function getBySiteAndFile ($site_id,$filename)
    {
        $sth = $this->dba->query("select * from "
            .$this->dba->tableforwarder
            ."_cmsTpl where site_id=$site_id and filename="
            .$this->dba->quote($filename).";");
        if (is_object($sth))
        {
            $row = $sth->fetch_row_Array();
            $sth->free();
            return $row;
        }
    }
    
    function getBySite ($site_id)
    {
        $sth = $this->dba->query("select * from "
            .$this->dba->tableforwarder
            ."_cmsTpl where site_id=$site_id order by type,name;");
        if (is_object($sth))
        {
            $rows = $sth->fetch_rows_Array();
            $sth->free();
            return $rows;
        }
    }

    function getBySiteAndType ($site_id,$type)
    {
        $sth = $this->dba->query("select * from "
            .$this->dba->tableforwarder
            ."_cmsTpl where site_id=$site_id and type="
            .$this->dba->quote($type)." order by name;");
        if (is_object($sth))
        {
            $rows = $sth->fetch_rows_Array();
            $sth->free();
            return $rows;
        }
    }

    function getall ()
    {
        $sth = $this->dba->query("select * from "
            .$this->dba->tableforwarder."_cmsTpl order by name;");
        if (is_object($sth))
        {
            $rows = $sth->fetch_rows_Array();
            $sth->free();
            return $rows;
        }
    }
    
    function isregistered ($filename,$site_id)
    {
        $sth = $this->dba->query("select id from "
            .$this->dba->tableforwarder
            ."_cmsTpl where site_id=$site_id and filename="
            .$this->dba->quote($filename).";");
        if (is_object($sth))
        {
            if ($sth->num_rows())
                return true;
        }
    }

}

?>